﻿using ShenNius.Blog.Common;
using ShenNius.Blog.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using ShenNius.Blog.Models;

namespace ShenNius.Blog.ViewComponents
{
    public class HeaderNavViewComponent : ViewComponent
    {
        private readonly IOptionsMonitor<SiteConfig> _siteConfig;

        public readonly HttpHelper _httpHelper;
        public HeaderNavViewComponent(HttpHelper httpHelper, IOptionsMonitor<SiteConfig> siteConfig)
        {
            _httpHelper = httpHelper;
            this._siteConfig = siteConfig;
        }
        public async Task<IViewComponentResult> InvokeAsync()
        {
            var model = await _httpHelper.GetAsync<ApiResult<List<CmsColumnVM>>>($"/api/index/get-all-column?siteId={_siteConfig.CurrentValue.GlobalSiteId}");
            return View(model?.Data);
        }
    }
}
